<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.5.0) on Thu May 15 17:17:33 EDT 2008 -->
<TITLE>
KeyField (Oracle - Berkeley DB Java API)
</TITLE>

<META NAME="keywords" CONTENT="com.sleepycat.persist.model.KeyField class">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../style.css" TITLE="Style">

<SCRIPT type="text/javascript">
function windowTitle()
{
    parent.document.title="KeyField (Oracle - Berkeley DB Java API)";
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>

</HEAD>

<BODY BGCOLOR="white" onload="windowTitle();">


<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/KeyField.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
<b>Berkeley DB</b><br><font size="-1"> version 4.7.25</font></EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../com/sleepycat/persist/model/FieldMetadata.html" title="class in com.sleepycat.persist.model"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../../com/sleepycat/persist/model/ModelInternal.html" title="class in com.sleepycat.persist.model"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  <A HREF="../../../../index.html?com/sleepycat/persist/model/KeyField.html" target="_top"><B>FRAMES</B></A>  &nbsp;
&nbsp;<A HREF="KeyField.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
&nbsp;<SCRIPT type="text/javascript">
  <!--
  if(window==top) {
    document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
  }
  //-->
</SCRIPT>
<NOSCRIPT>
  <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>


</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  SUMMARY:&nbsp;<A HREF="#annotation_type_required_element_summary">REQUIRED</A>&nbsp;|&nbsp;OPTIONAL</FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;<A HREF="#annotation_type_element_detail">ELEMENT</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->

<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
com.sleepycat.persist.model</FONT>
<BR>
Annotation Type KeyField</H2>
<HR>
<DL>
<DT><PRE><FONT SIZE="-1"><A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Documented.html" title="class or interface in java.lang.annotation">@Documented</A>
<A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Retention.html" title="class or interface in java.lang.annotation">@Retention</A>(<A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Retention.html#value()" title="class or interface in java.lang.annotation">value</A>=<A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/RetentionPolicy.html#RUNTIME" title="class or interface in java.lang.annotation">RUNTIME</A>)
<A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Target.html" title="class or interface in java.lang.annotation">@Target</A>(<A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Target.html#value()" title="class or interface in java.lang.annotation">value</A>=<A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/ElementType.html#FIELD" title="class or interface in java.lang.annotation">FIELD</A>)
</FONT>public @interface <B>KeyField</B></DL>
</PRE>

<P>
Indicates the sorting position of a key field in a composite key class when
 the <code>Comparable</code> interface is not implemented.  The <code>KeyField</code>
 integer value specifies the sort order of this field within the set of
 fields in the composite key.

 <p>If the field type of a <A HREF="../../../../com/sleepycat/persist/model/PrimaryKey.html" title="annotation in com.sleepycat.persist.model"><CODE>PrimaryKey</CODE></A> or <A HREF="../../../../com/sleepycat/persist/model/SecondaryKey.html" title="annotation in com.sleepycat.persist.model"><CODE>SecondaryKey</CODE></A> is a
 composite key class containing more than one key field, then a <code>KeyField</code> annotation must be present on each non-transient instance field of
 the composite key class.  The <code>KeyField</code> value must be a number
 between one and the number of non-transient instance fields declared in the
 composite key class.</p>

 <p>Note that a composite key class is a flat container for one or more
 simple type fields.  All non-transient instance fields in the composite key
 class are key fields, and the composite key class may not have superclasses
 containing non-transient instance fields.</p>

 <p>For example:</p>
 <pre class="code">
  @Entity
  class Animal {
      @PrimaryKey
      Classification classification;
      ...
  }

  @Persistent
  class Classification {
      @KeyField(1) String kingdom;
      @KeyField(2) String phylum;
      @KeyField(3) String clazz;
      @KeyField(4) String order;
      @KeyField(5) String family;
      @KeyField(6) String genus;
      @KeyField(7) String species;
      @KeyField(8) String subspecies;
      ...
  }</pre>

 <p>This causes entities to be sorted first by <code>kingdom</code>, then by
 <code>phylum</code> within <code>kingdom</code>, and so on.</p>

 <p>The fields in a composite key class may not be null.</p>

 <p><a name="comparable"><strong>Custom Sort Order</strong></a></p>

 <p>To override the default sort order, a composite key class may implement
 the <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html" title="class or interface in java.lang"><CODE>Comparable</CODE></A> interface.  This allows overriding the sort order and
 is therefore useful even when there is only one key field in the composite
 key class.  For example, the following class sorts Strings using a Canadian
 collator:</p>

 <pre class="code">
  import java.text.Collator;
  import java.util.Locale;

  @Entity
  class Animal {
      ...
      @SecondaryKey(relate=ONE_TO_ONE)
      CollatedString canadianName;
      ...
  }

  @Persistent
  class CollatedString implements Comparable&lt;CollatedString&gt; {

      static Collator collator = Collator.getInstance(Locale.CANADA);

      @KeyField(1)
      String value;

      CollatedString(String value) { this.value = value; }

      private CollatedString() {}

      public int compareTo(CollatedString o) {
          return collator.compare(value, o.value);
      }
  }</pre>

 <p>Several important rules should be considered when implementing a custom
 comparison method.  Failure to follow these rules may result in the primary
 or secondary index becoming unusable; in other words, the store will not be
 able to function.</p>
 <ol>
 <li>The comparison method must always return the same result, given the same
 inputs.  The behavior of the comparison method must not change over
 time.</li>
 <br>
 <li>A corollary to the first rule is that the behavior of the comparison
 method must not be dependent on state which may change over time.  For
 example, if the above collation method used the default Java locale, and the
 default locale is changed, then the sort order will change.</li>
 <br>
 <li>The comparison method must not assume that it is called after the store
 has been opened.  With Berkeley DB Java Edition, the comparison method is
 called during database recovery, which occurs in the <A HREF="../../../../com/sleepycat/db/Environment.html" title="class in com.sleepycat.db"><CODE>Environment</CODE></A>
 constructor.</li>
 <br>
 <li>The comparison method must not assume that it will only be called with
 keys that are currently present in the database.  The comparison method will
 occasionally be called with deleted keys or with keys for records that were
 not part of a committed transaction.</li>
 </ol>
<P>

<P>
<HR>

<P>
<!-- =========== ANNOTATION TYPE REQUIRED MEMBER SUMMARY =========== -->

<A NAME="annotation_type_required_element_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Required Element Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/sleepycat/persist/model/KeyField.html#value()">value</A></B></CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
</TR>
</TABLE>
&nbsp;
<P>

<!-- ============ ANNOTATION TYPE MEMBER DETAIL =========== -->

<A NAME="annotation_type_element_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Element Detail</B></FONT></TH>
</TR>
</TABLE>

<A NAME="value()"><!-- --></A><H3>
value</H3>
<PRE>
public abstract int <B>value</B></PRE>
<DL>
<DD><DL>
</DL>
</DD>
<DD><DL>
</DL>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>


<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
  <TR ALIGN="center" VALIGN="top">
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/KeyField.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
  </TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
<b>Berkeley DB</b><br><font size="-1"> version 4.7.25</font></EM>
</TD>
</TR>

<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../com/sleepycat/persist/model/FieldMetadata.html" title="class in com.sleepycat.persist.model"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../../com/sleepycat/persist/model/ModelInternal.html" title="class in com.sleepycat.persist.model"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
  <A HREF="../../../../index.html?com/sleepycat/persist/model/KeyField.html" target="_top"><B>FRAMES</B></A>  &nbsp;
&nbsp;<A HREF="KeyField.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;
&nbsp;<SCRIPT type="text/javascript">
  <!--
  if(window==top) {
    document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
  }
  //-->
</SCRIPT>
<NOSCRIPT>
  <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>


</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
  SUMMARY:&nbsp;<A HREF="#annotation_type_required_element_summary">REQUIRED</A>&nbsp;|&nbsp;OPTIONAL</FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;<A HREF="#annotation_type_element_detail">ELEMENT</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->

<HR>
<font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
</BODY>
</HTML>
